package com.example.kotlinstudy.基本类型

fun main() {
    val obj = "";
    if (obj is String) {
        print("a String")
    }
    if (obj !is String) {
        print("Not a String")
    } else {
        print(obj.length)
    }
    //不安全的转换操作符
    val y = 1
    val x: String? = y as? String?
}

//智能转换类型
fun demo(x: Any) {
    if (x is String) {
        print(x.length)
    }
    if (x !is String) return
    print(x.length)
    if (x !is String || x.length == 0) {

    }
    if (x is String && x.length > 0) {
        print(x.length)
    }
    when (x) {
        is Int -> print(x + 1)
        is String -> print(x.length + 1)
        is IntArray -> print(x.sum())
    }
}